<!-- 模块说明 -->
<template>
  <div>
    <Form
      :options="options"
      :options2="options2"
      :getId="getId"
      :submitList="submitList"
      :gettId="gettId"

      @onSumbit="onSumbit"
    ></Form>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from "vue";
import Form from "../../components/form/index.vue";
import {useStore} from 'vuex'
import { getGradeList, getSubjectList } from "../../api/index";
import {
  IQuestion,
  addQuestionList,
  editQuestionList,
} from "../../api/question";
import { useRoute, useRouter } from "vue-router";
const route = useRoute();
const router = useRouter();
const store = useStore()
const options = ref<any[]>([]);
const options2 = ref<any[]>([]);
const submitList = ref<IQuestion>(route.query.id ? store.state.topic.profile : {
  id: 0,
  questionType: 0,
  subjectId: 0,
  score: 0,
  correct: "",
  difficult: 0,
  shortTitle: "",
});
const getGrade = async () => {
  let res = await getGradeList();
  options.value = res.data;
  // console.log(res);
};
const getId = async (item: any) => {
  // console.log(item.id);
  let res = await getSubjectList({ level: item.id });
  options2.value = res.data;
};

const count = ref<number>(0);
const gettId = (item: any) => {
  count.value = item.xueid;
};

const onSumbit = async (form: any) => {
  console.log(submitList.value,'cao');
  // console.log(form);
   submitList.value = ({
    id: Date.now(),
    questionType: 5,
    subjectId: count,
    score: form.score,
    correct: form.correct,
    difficult: form.difficult,
    shortTitle: form.shortTitle,
  });
  if (route.query.id !== undefined) {
    await editQuestionList(route.query.id, submitList.value);
  } else {
    await addQuestionList(submitList.value);
  }
  router.push("/topic");
};
onMounted(() => {
  getGrade();
});
</script>
<style lang="scss" scoped></style>
